<?php

namespace App\Admin\Extensions\Navs;

use App\Models\HelpWorkOrder;
use App\Models\Payment;

class Messages
{
    public function __toString()
    {
        $title = trans('admin.new_notification');

        $wo_msg = $this->getHelpWorkOrder();
        $wd_msg = $this->getWithdraw();
        $tu_msg = $this->getTopUp();

        $total_msg = $wo_msg + $wd_msg + $tu_msg;

        $wo_route = route('help_center.index');
        $wd_route = route('withdraws.index');
        $tu_route = route('top_up_apply.index');

        $work_order_message = trans('admin.new_work_order');
        $withdraw_message = trans('admin.new_withdraw');
        $top_up_message = trans('admin.new_top_up');

        $html = '';
        $html .= '<li class="dropdown notifications-menu">';
        $html .= '<a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">';
        $html .= '<i class="fa fa-bell-o"></i>';
        $html .= '<span class="label label-warning">' . $total_msg . '</span>';
        $html .= '</a>';
        $html .= '<ul class="dropdown-menu">';
        $html .= '<li class="header">' . $title . '</li>';
        $html .= '<li>';
        $html .= '<!-- inner menu: contains the actual data -->';
        $html .= '<ul class="menu">';
        if ($wo_msg) {
            $html .= '<li>';
            $html .= '<a href="' . $wo_route . '">';
            $html .= '<i class="fa fa-users text-aqua"></i> ' . $work_order_message . ' <span class="badge bg-yellow" style="line-height: normal">' . $wo_msg . '</span>';
            $html .= '</a>';
            $html .= '</li>';
        }
        if ($wd_msg) {
            $html .= '<li>';
            $html .= '<a href="' . $wd_route . '">';
            $html .= '<i class="fa fa-cc-paypal text-aqua"></i> ' . $withdraw_message . ' <span class="badge bg-red" style="line-height: normal">' . $wd_msg . '</span>';
            $html .= '</a>';
            $html .= '</li>';
        }
        if ($tu_msg) {
            $html .= '<li>';
            $html .= '<a href="' . $tu_route . '">';
            $html .= '<i class="fa fa-dollar text-aqua"></i> ' . $top_up_message . ' <span class="badge bg-blue" style="line-height: normal">' . $tu_msg . '</span>';
            $html .= '</a>';
            $html .= '</li>';
        }
        $html .= '</ul>';
        $html .= '</li>';
        $html .= '<!--<li class="footer"><a href="$route">View all</a></li>-->';
        $html .= '</ul>';
        $html .= '</li>';

        return $html;
    }

    //工單
    public function getHelpWorkOrder()
    {
        return $work_order = HelpWorkOrder::where('p_id', 0)->where('is_close', 0)->count();
    }

    //提現
    public function getWithdraw()
    {
        return Payment::where('action', Payment::WITHDRAW)->where('status', Payment::PENDING)->count();
    }

    //充值
    public function getTopUp()
    {
        return Payment::where('action', Payment::TOP_UP)->where('status', Payment::PENDING)->count();
    }
}
